package com.glory.brepda.activity.check;

import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.glory.brepda.R;
import com.glory.brepda.base.BaseActivity;
import com.glory.brepda.callback.CustomDialogEntityCallBack;
import com.glory.brepda.entity.response.BaseResponseBean;
import com.glory.brepda.utils.NetUtils;
import com.google.gson.JsonObject;
import com.google.gson.reflect.TypeToken;
import com.lzy.okgo.model.Response;
import com.pda.platform.ui.ui_pdaplatform.callback.FreeUI_EntityCallBack;
import com.pda.platform.ui.ui_pdaplatform.view.FreeUI_ClearEditText;

import org.json.JSONObject;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

import butterknife.BindView;

public class QCSampleReceivingActivity extends BaseActivity {

    @BindView(R.id.llMain)
    LinearLayout llMain;
    @BindView(R.id.tvTitle)
    TextView tvTitle;
    @BindView(R.id.tvBaseSubmit)
    TextView tvBaseSubmit;
    @BindView(R.id.etWorkID)
    FreeUI_ClearEditText etWorkID;

    @Override
    protected int getLayoutResId() {
        return R.layout.activity_qcsample_receiving;
    }

    @Override
    protected void initView() {

        setMainLayout(llMain);
        tvTitle.setText("QC检验样品接收");
        tvBaseSubmit.setVisibility(View.GONE);

    }

    @Override
    protected void initData() {

        initEdit(etWorkID,s->{
            queryGroupId();
        });

    }

    private void queryGroupId(){

        FreeUI_EntityCallBack<BaseResponseBean<JSONObject>> callBack = new CustomDialogEntityCallBack<BaseResponseBean<JSONObject>>
                (new TypeToken<BaseResponseBean<JSONObject>>() {
                }.getType(), getSupportFragmentManager(), this) {

            @Override
            public void onSuccess(Response<BaseResponseBean<JSONObject>> response) {
                super.onSuccess(response);
                if (response.body().isSuccess(getApplicationContext(), false, getSupportFragmentManager())) {
                    showToast("操作成功", true);
                }
            }

            @Override
            public void onError(Response<BaseResponseBean<JSONObject>> response) {
                super.onError(response);
                loadError(response.getException(), "QCFORMRECEIVETIME");
            }
        };
        JsonObject map = new JsonObject();
        map.addProperty("RECEIVETIME", getCurrentTimeFormatted());
        map.addProperty("GROUPID", getText(etWorkID));
        NetUtils.requestPostNet("IF.QCFORMRECEIVETIME", "Common", QCSampleReceivingActivity.this, map, callBack);



    }

    public String getCurrentTimeFormatted() {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss", Locale.getDefault());
        return sdf.format(new Date());
    }


}